<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    iframe2
    <script>
        var myName = 'iframe2';
        console.log(window.parent);
        console.log(window.parent.myName);
        console.log(window.parent.parent.myName);
        // 通过window.top可以获得嵌套iframe的顶级窗口
        console.log(window.top.myName);
        console.log('---------------------------------');
    </script>
</body>

</html>